package com.wxd.controller;

import com.wxd.dao.UserMapper;
import com.wxd.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/list")
    public List<User> list() {
        return userMapper.findList();
    }

    @RequestMapping("/add")
    public Integer add(User user) {
        return userMapper.insert(user);
    }

    @RequestMapping("/addAll")
    public Integer addAll() {
        int index = 0;
        for (long i = 1; i <= 1000; i++) {
            User user = new User();
            user.setId(i);
            user.setName("tom" + i);
            userMapper.insert(user);
            index++;
        }
        return index;
    }
}
